from PyQt5.Qt import *


class SzLabel(QLabel):

    def mousePressEvent(self, evt):
        # 获取鼠标对象evt
        super().mousePressEvent(evt)
        # 设置控件属性
        point = QPushButton(self)
        point.resize(20, 20)
        point.move(evt.pos() - QPoint(10, 10))
        point.setStyleSheet("background: green; border-radius: 10px")
        # 显示控件
        point.show()
        # 删除控件
        point.clicked.connect(lambda _, btn=point: btn.deleteLater())

    def get_coordinate(self):
        coordinate = ",".join(["{},{}".format(child.x() + 10, child.y() - 20) for child in
                               self.children() if child.inherits("QPushButton")])
        print(coordinate)
        return coordinate
        # for child in self.children():
        #     if child.inherits("QPushButton"):
        #         s1 = ["{},{}".format(child.x() + 10, child.y() - 20)]
        #         print(s1)
        #         s = ",".join("{},{}".format(child.x() + 10, child.y() - 20))
        #         print(s)

    def clear_points(self):
        [child.deleteLater() for child in self.children() if child.inherits("QPushButton")]
